package com.sline.chario;

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class Demo8_ByteArrayOutputStream {
    public static void main(String[] args) throws IOException {
        // demo1();

        // demo2();

        Properties prop = new Properties();
        prop.load(new FileInputStream("config.properties"));
        System.out.println(prop);
        prop.setProperty("tel", "18121253012");
        System.out.println(prop);
        prop.store(new FileOutputStream("config.properties"), "S_Line");
    }

    private static void demo2() throws IOException {
    /*
    * 定义一个文件输入流, 调用read(byte[] b)方法, 将abc.txt文件中的内容打印出来(byte数组大小限制为5个)
    * */

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        FileInputStream fis = new FileInputStream("abc.txt");

        byte[] b = new byte[5];
        int len;
        while ((len = fis.read(b)) != -1) {
            baos.write(b,0,len);
        }

        System.out.println(baos.toString());
        fis.close();
    }

    private static void demo1() throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        FileInputStream fis = new FileInputStream("abc.txt");

        int b;
        while ((b = fis.read()) != -1) {
            baos.write(b);
        }

        System.out.println(baos.toString());
        fis.close();
    }
}
